package com.haircut.sys.controller.role;

import com.haircut.sys.service.role.IRoleService;
import com.haircut.sys.vo.role.ReolePageReqVo;
import com.haircut.sys.vo.role.RolePageResVo;
import com.haircut.sys.vo.role.RoleReqVo;
import com.haircut.sys.vo.role.RoleVo;
import com.modular.result.PageResult;
import com.modular.result.RspMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/b/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    /**
     * 新增角色
     * @param reqVo
     * @return
     */
    @ApiOperation(value = "新增角色")
    @PostMapping("saveRole")
    public RspMessage<Void> saveRole(@Validated @RequestBody RoleReqVo reqVo){
        roleService.saveRole(reqVo);
        return RspMessage.success();
    }
    /**
     * 修改角色
     * @param reqVo
     * @return
     */
    @ApiOperation(value = "修改角色")
    @PostMapping("modifyRole")
    public RspMessage<Void> modifyRole(@Validated @RequestBody RoleReqVo reqVo){
        roleService.modifyRole(reqVo);
        return RspMessage.success();
    }
    /**
     * 删除角色
     * @param roleId
     * @return
     */
    @ApiOperation(value = "删除角色")
    @GetMapping("deleteById")
    public RspMessage<Void> deleteById(@ApiParam("角色id") @RequestParam("roleId") String roleId){
        roleService.deleteById(roleId);
        return RspMessage.success();
    }
    /**
     * 查询角色详情
     * @param roleId
     * @return
     */
    @ApiOperation(value = "查询角色详情")
    @GetMapping("findDetail")
    public RspMessage<RoleVo> findDetail(@ApiParam("角色id") @RequestParam("roleId") String roleId){
        return RspMessage.success(roleService.findDetail(roleId));
    }
    /**
     * 查询角色列表
     */
    @ApiOperation(value = "查询角色列表")
    @PostMapping("findPage")
    public RspMessage<PageResult<RolePageResVo>> findPage(@RequestBody ReolePageReqVo reqVo){
        return RspMessage.success(roleService.findPage(reqVo));
    }
    /**
     * 查询所欲的角色
     */
    @ApiOperation(value = "查询所欲的角色")
    @GetMapping("findAll")
    public RspMessage<List<RolePageResVo>> findAll(){
        return RspMessage.success(roleService.findAll());
    }


}
